package com.hk.controller;

import com.hk.auth.SpaceUserPermissionConstant;
import com.hk.auth.annotation.SaSpaceCheckPermission;
import com.hk.common.ResponseResult;
import com.hk.model.vo.IdVO;
import com.hk.model.vo.spaceuser.SpaceUserAddVO;
import com.hk.model.vo.spaceuser.SpaceUserBatchAddVO;
import com.hk.model.vo.spaceuser.SpaceUserEditVO;
import com.hk.model.vo.spaceuser.SpaceUserVO;
import com.hk.service.SpaceUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author huangkun
 * @date 2024/12/11 21:51
 */
@RestController
//@Api(value = "空间成员管理", tags = "空间成员管理")
@RequestMapping("/spaceUser")
public class SpaceUserController {

    @Resource
    private SpaceUserService spaceUserService;


    @ApiOperation(value = "添加空间成员")
    @PostMapping("/add")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.SPACE_USER_MANAGE)
    public ResponseResult<Boolean> addSpaceUser(@RequestBody SpaceUserAddVO spaceUserAddVO) {
        return ResponseResult.success(spaceUserService.addSpaceUser(spaceUserAddVO));
    }

    @ApiOperation(value = "批量添加空间成员")
    @PostMapping("/batch/add")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.SPACE_USER_MANAGE)
    public ResponseResult<Boolean> batchAddSpaceUser(@RequestBody SpaceUserBatchAddVO batchAddVO) {
        return ResponseResult.success(spaceUserService.batchAddSpaceUser(batchAddVO));
    }

    @ApiOperation(value = "修改空间成员")
    @PostMapping("/edit")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.SPACE_USER_MANAGE)
    public ResponseResult<Boolean> editSpaceUser(@RequestBody SpaceUserEditVO spaceUserEditVO) {
        return ResponseResult.success(spaceUserService.editSpaceUser(spaceUserEditVO));
    }


    @ApiOperation(value = "获取空间成员列表")
    @GetMapping("/get/user/list")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.SPACE_USER_MANAGE)
    public ResponseResult<List<SpaceUserVO>> selectUserListBySpaceId(@RequestParam Long spaceId, @RequestParam(required = false) String spaceRole) {
        return ResponseResult.success(spaceUserService.selectUserListBySpaceId(spaceId, spaceRole));
    }

    @ApiOperation(value = "获取用户加入的空间列表")
    @GetMapping("/get/space/list")
    public ResponseResult<List<SpaceUserVO>> selectSpaceListByUserId(@RequestParam Long userId) {
        return ResponseResult.success(spaceUserService.selectSpaceListByUserId(userId));
    }


    @ApiOperation(value = "删除空间成员")
    @PostMapping("/delete")
    @SaSpaceCheckPermission(value = SpaceUserPermissionConstant.SPACE_USER_MANAGE)
    public ResponseResult deleteSpaceUser(@RequestBody IdVO idVO) {
        spaceUserService.removeById(idVO.getId());
        return ResponseResult.success();
    }



}

